﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace WPAChess
{
    public class Location
    {
        private byte row;
        private byte col;
        public Location(byte row, byte col)
        {
            this.row = row;
            this.col = col;
        }

        public byte Row
        {
            get
            {
                return this.row;
            }
        }

        public byte Column
        {
            get
            {
                return this.col;
            }
        }
    }

    public static class Pieces
    {
        public const byte black = 0;
        public const byte white = 8;

        public const byte empty = 0;
        public const byte pawn = 1;
        public const byte rook = 4;
        public const byte knight = 2;
        public const byte bishop = 3;
        public const byte king = 6;
        public const byte queen = 5;
    }
    /// <summary>
    /// lop the hien vi tri cua cac quan co
    /// </summary>
    public class Position  
    {
        public byte[][] Board = new byte[8][];
        public Location[] pieceList = new Location[32];

        
        public byte ToMove;

        public void ResetBoard()
        {
            this.ToMove = Pieces.white;

            //khoi tao this.Board
            for (byte i = 0; i < 8; ++i) this.Board[i] = new byte[8];
            for (int i = 0; i < 8; ++i)
            {
                for (int j = 0; j < 8; ++j)
                {
                    this.Board[i][j] = Pieces.empty; 
                }
            }

            for (int i = 0; i < 8; ++i)
            {
                this.Board[6][i] = (Pieces.white | Pieces.pawn); 
            }

            for (int i = 0; i < 8; ++i)
            {
                this.Board[1][i] = (Pieces.black | Pieces.pawn);
            }

            this.Board[7][0] = (Pieces.white | Pieces.rook);
            this.Board[7][7] = (Pieces.white | Pieces.rook);
            this.Board[7][1] = (Pieces.white | Pieces.knight);
            this.Board[7][6] = (Pieces.white | Pieces.knight);
            this.Board[7][2] = (Pieces.white | Pieces.bishop);
            this.Board[7][5] = (Pieces.white | Pieces.bishop);
            this.Board[7][3] = (Pieces.white | Pieces.queen);
            this.Board[7][4] = (Pieces.white | Pieces.king);

            this.Board[0][0] = (Pieces.black | Pieces.rook);
            this.Board[0][7] = (Pieces.black | Pieces.rook);
            this.Board[0][1] = (Pieces.black | Pieces.knight);
            this.Board[0][6] = (Pieces.black | Pieces.knight);
            this.Board[0][2] = (Pieces.black | Pieces.bishop);
            this.Board[0][5] = (Pieces.black | Pieces.bishop);
            this.Board[0][3] = (Pieces.black | Pieces.queen);
            this.Board[0][4] = (Pieces.black | Pieces.king);

            InitilazationPositionPieces();
        }

        /// <summary>
        /// lay nhung vi tri co chua quan co
        /// </summary>
        private void InitilazationPositionPieces()
        {
            for (byte i = 0; i < 32; ++i) this.pieceList[i] = null;

            byte count = 0;

            for (byte i = 0; i < 8; ++i)
            {
                for (byte j = 0; j < 8; ++j)
                {
                    if (this.Board[i][j] != Pieces.empty)
                    {
                        this.pieceList[count] = new Location(i, j);
                        count++;
                    }
                }
            }
        }

        
    }
     
    





    public sealed class Robus
    {
    }

    //public class Piece
    //{
    //    private byte name;
    //    private bool hasMoved = false;
    //    private int player;
    //    private Square square;


    //    public Piece(byte name, Square square, int player)
    //    {
    //        this.name = name;
    //        this.square = square;
    //        this.player = player;
    //    }

    //    public void Move()
    //    {
    //    }
    //}



    //public sealed class PiecePawn : Piece
    //{

    //}

    //public sealed class PieceBishop : Piece
    //{
    //}

    //public sealed class PieceKnight : Piece
    //{
    //}

    //public sealed class PieceRook : Piece
    //{
    //}

    //public sealed class PieceQueen : Piece
    //{
    //}

    //public sealed class PieceKing : Piece
    //{
    //}

    
}
